//
//  MainViewController.m
//  Photo
//
//  Created by dllo on 15/11/5.
//  Copyright (c) 2015年 Zebra. All rights reserved.
//

#import "MainViewController.h"
#import "SecondViewController.h"
@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor grayColor];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBarHidden = NO;
    self.navigationItem.title = @"相册导航";
    NSInteger k = 1;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(20 + j * ((self.view.frame.size.width  - 20) / 3), 25 + 200 * i, (self.view.frame.size.width  - 20) / 3 - 20, 150)];
            scroll.backgroundColor = [UIColor blackColor];
            [self.view addSubview:scroll];
            [scroll release];
            NSString *str = [NSString stringWithFormat:@"%ld.jpg", k];
            UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
            button.frame = CGRectMake(0, 0, scroll.frame.size.width, scroll.frame.size.height);
            [button setBackgroundImage:[UIImage imageNamed:str] forState:UIControlStateNormal];
            [scroll addSubview:button];
            button.tag = k;
            [button addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];
            k++;
        }
    }
    
    

    
    
    
    
    
    
    
    
    // Do any additional setup after loading the view.
}


- (void)tapAction:(UIButton *)sender {
    SecondViewController *second = [[SecondViewController alloc] init];
    UIScrollView *scroll = (UIScrollView *)[second.view viewWithTag:100];
    scroll.contentOffset = CGPointMake((sender.tag - 1) * scroll.bounds.size.width, 0);
    [self.navigationController pushViewController:second animated:YES];
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
